<?php
namespace Admin\Controller;
use Think\Controller;
use Think\Page;
	class CategoryController extends CommonController{
	
		
		public function index(){
			
			$cate = M('Category'); 
			$count      = $cate->count();
			$Page       = new Page($count,6);
			$show       = $Page->show();
			
			$list = $cate->limit($Page->firstRow.','.$Page->listRows)->select();
			$this->assign('data',$list);
			$this->assign('page',$show);
			
			$this->display('Category/index');
		}
		
		
		public function checkcate(){
			$cate=M('Category');
			$data = array('name'=>$_POST['name']);
			$count = $cate-> where($data)->find();
			if($count == null){
				$this->show("error");
			}else{
				$this->show("ok");
			}
		}
		
		public function del(){
			$m=M('Category');
			$id=$_GET['id'];
			
			$art = M('Article');
			$num = $art->where('category_id='.$id)->count();
			if($num>0){
				$this->error('此分类下还有新闻，无法删除');
			}
			$count=$m->delete($id);
			if($count>0){
				$this->success('删除分类成功');
			}else{
				$this->error('删除失败');
			}
		}
		
	}
?>
